package com.apes.framework.plugin.form.parser.element;

import com.apes.framework.plugin.filereader.xml.ApesElement;
import com.apes.framework.plugin.filereader.xml.ApesElementParser;
import com.apes.framework.plugin.form.parser.node.FormNodeParser;
import com.apes.framework.util.Tools;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 功能：depends解析
 *
 * @author xul
 * @create 2018-06-12 15:02
 */
@Component
public class EventElementParser implements ApesElementParser<ApesElement, Map> {
    /**
     * 可解析的元素列表
     **/
    private final String[] elementNames = {"event"};

    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return FormNodeParser.domain;
    }

    /**
     * 功能：可解析的元素列表
     */
    @Override
    public String[] getNames() {
        return elementNames;
    }

    /**
     * 功能：元素解析
     *
     * @param element
     */
    @Override
    public Map parse(ApesElement element) {
        if (!element.getAttributes().containsKey("type") || Tools.isNull(element.getAttributes().get("type")) || Tools.isNull(element.getText()))
            return null;
        Map result = new HashMap();
        result.put("type", element.getAttributes().get("type"));
        result.put("callback", element.getText());
        return result;
    }
}
